package ar.uba.dc.webming.tp1.relevance;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

public class RelevanceJudgementMap {
    private Map<String,List<RelevanceJudgment>> indexedJudgments;
    
    public RelevanceJudgementMap(List<RelevanceJudgment> judgments){
        indexedJudgments = new HashMap<String, List<RelevanceJudgment>>();
        Iterator<RelevanceJudgment> judgeIt = judgments.iterator();
        while (judgeIt.hasNext()) {
            RelevanceJudgment aJudgment = (RelevanceJudgment) judgeIt
                    .next();
            if(indexedJudgments.containsKey(aJudgment.getQueryNum())){
                indexedJudgments.get(aJudgment.getQueryNum()).add(aJudgment);
            }else{
                List<RelevanceJudgment> rjList = new Vector<RelevanceJudgment>();
                rjList.add(aJudgment);
                indexedJudgments.put(aJudgment.getQueryNum(), rjList);
            }
        }
    }
    
    public List<RelevanceJudgment> get(String queryNum){
        return indexedJudgments.get(queryNum);
    }
    
    public boolean isRelevantForQuery(String queryNum, String docNum){
        Iterator<RelevanceJudgment> itJudg = get(queryNum).iterator();
        while (itJudg.hasNext()) {
            RelevanceJudgment relevanceJudgment = (RelevanceJudgment) itJudg
                    .next();
            if(relevanceJudgment.getDocNum().equals(docNum)){
                return true;
            }
        }
        return false;
    }
}
